package com.osce.basic.controller;

import com.csce.domain.entity.basic.BasicBase;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.basic.IBasicBaseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学科表Controller
 *
 * @author zzx
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/basic/base")
public class BasicBaseController extends BaseController {

    @Resource
    private IBasicBaseService basicBaseService;

    /**
     * 查询学科表列表
     */
    @PreAuthorize("@ss.hasPermi('basic:base:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicBase basicBase) {
        startPage();
        List<BasicBase> list = basicBaseService.selectBasicBaseList(basicBase);
        return getDataTable(list);
    }

    /**
     * 导出学科表列表
     */
    @PreAuthorize("@ss.hasPermi('basic:base:export')")
    @Log(title = "学科表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicBase basicBase) {
        List<BasicBase> list = basicBaseService.selectBasicBaseList(basicBase);
        ExcelUtil<BasicBase> util = new ExcelUtil<BasicBase>(BasicBase.class);
        util.exportExcel(response, list, "学科表数据");
    }

    /**
     * 获取学科表详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:base:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(basicBaseService.selectBasicBaseById(id));
    }

    /**
     * 新增学科表
     */
    @PreAuthorize("@ss.hasPermi('basic:base:add')")
    @Log(title = "学科表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicBase basicBase) {
        return toAjax(basicBaseService.insertBasicBase(basicBase));
    }

    /**
     * 修改学科表
     */
    @PreAuthorize("@ss.hasPermi('basic:base:edit')")
    @Log(title = "学科表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicBase basicBase) {
        return toAjax(basicBaseService.updateBasicBase(basicBase));
    }

    /**
     * 删除学科表
     */
    @PreAuthorize("@ss.hasPermi('basic:base:remove')")
    @Log(title = "学科表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(basicBaseService.deleteBasicBaseByIds(ids));
    }
}
